<template>
    <div class="tabs" @click="changeMenu(item)"><el-tag v-for="(item, index) in tags" :key="item.path"
            :closable="item.name !== 'home'" :effect="$route.name === item.name ? 'dark' : 'plain'"
            @click="changeMenu(item)" @close="closeMenu(item, index)">
            {{ item.label }}
        </el-tag>
    </div>
</template>


<script>
import { mapState } from 'vuex'
export default {
    name: 'CommonTag',
    data() {
        return {}
    },
    computed: {
        ...mapState({
            tags: state => state.tab.tabList
        })
    },
    methods: {
        changeMenu(item) {
            this.$router.push(item.path)

        },
        closeMenu(item, index) {
            this.tags.splice(this.tags.indexOf(item), 1)
            if (item.name === this.$route.name) {
                index === this.tags.length ? this.$router.push({
                    name: this.tags[index - 1].name
                }) : this.$router.push({
                    name: this.tags[index].name
                })

            }

        }

    }
}
</script>

<style lang="less" >
.tabs {
    padding: 20px;



    .el-tag {
        margin-right: 15px;
        cursor: pointer;

    }
}
</style>